namespace AutoTest.Console
{
    using System;
    using Core.Configuration;
    using Core.FileSystem;
    using log4net;
    using Ninject.Core;

    public class ConsoleApplication : IStartable
    {
        private readonly IDirectoryWatcher _watcher;
        private readonly ISettingService _settingService;
        private readonly ILog _logger = LogManager.GetLogger(typeof (ConsoleApplication));

        public ConsoleApplication(IDirectoryWatcher watcher, ISettingService settingService)
        {
            _watcher = watcher;
            _settingService = settingService;
        }

        public void Start()
        {
            _logger.InfoFormat("Starting AutoTester and watching \"{0}\" and all subdirectories.", _settingService.DirectoryToWatch);
            _watcher.Watch(_settingService.DirectoryToWatch);
            Console.ReadLine();
            Stop();
        }

        public void Stop()
        {
            _watcher.Dispose();
        }
    }
}